<script type="text/javascript">
	function requestMarkAsReadAndUnRead(notification_id, aTAG){
		if($(aTAG).text()=="Mark as read"){
			showLoading();
			$.ajax({ 
				url:"${pageContext.request.contextPath}/account/mark-noty-read.html",    
				type:"POST", 
				contentType: "application/json; charset=utf-8",
				data: notification_id, //Stringified Json Object
				success: function(response){
					$(aTAG).text('Mark as unread');
					var divNotificationBackground = $(aTAG).closest('div').closest('div').closest('div').parent();
					$(divNotificationBackground).removeClass("notification-center-message-background-unread");
					$(divNotificationBackground).addClass("notification-center-message-background-read");
					unShowLoading();
				}});
		}else{
			showLoading();
			$.ajax({ 
				url:"${pageContext.request.contextPath}/account/mark-noty-unread.html",    
				type:"POST", 
				contentType: "application/json; charset=utf-8",
				data: notification_id, //Stringified Json Object
				success: function(response){
					$(aTAG).text('Mark as read');
					var divNotificationBackground = $(aTAG).closest('div').closest('div').closest('div').parent();
					$(divNotificationBackground).removeClass("notification-center-message-background-read");
					$(divNotificationBackground).addClass("notification-center-message-background-unread");
					unShowLoading();
				}});
		}
	}

	function setReadWhenLinkToSuscribe(notification_id){
			$.ajax({ 
				url:"${pageContext.request.contextPath}/account/mark-noty-read.html",    
				type:"POST", 
				contentType: "application/json; charset=utf-8",
				data: notification_id, //Stringified Json Object
				success: function(response){
				}});
	}
	
	
	function requestToDeleteOne(notification_id, aTAG){
		showLoading();
		$.ajax({ 
			url:"${pageContext.request.contextPath}/account/delete-noty.html",    
			type:"POST", 
			contentType: "application/json; charset=utf-8",
			data: notification_id, //Stringified Json Object
			success: function(response){
				var divNotificationBackground = $(aTAG).closest('div').parent();
 				$(divNotificationBackground).remove();
				function stickyFooter() {
			         var footer = $("#footer");
			         var pos = footer.position();
			         var height = $(window).height();
			         height = height - pos.top;
			         height = height - footer.outerHeight();

			         if (height > 0) {
			          footer.css({
			           'margin-top': height + 'px'
			          });
			         }
			    };
				location.reload();				
				unShowLoading();
				stickyFooter();
			}});
	}
	
	function requestToDeleteOneTask(notification_id, aTAG){
		showLoading();
		$.ajax({ 
			url:"${pageContext.request.contextPath}/account/delete-noty-task.html",    
			type:"POST", 
			contentType: "application/json; charset=utf-8",
			data: notification_id, //Stringified Json Object
			success: function(response){
				var divNotificationBackground = $(aTAG).closest('div').parent();
 				$(divNotificationBackground).remove();
				function stickyFooter() {
			         var footer = $("#footer");
			         var pos = footer.position();
			         var height = $(window).height();
			         height = height - pos.top;
			         height = height - footer.outerHeight();

			         if (height > 0) {
			          footer.css({
			           'margin-top': height + 'px'
			          });
			         }
			    };
				location.reload();				
				unShowLoading();
				stickyFooter();
			}});
	}
	
	function requestToDeleteAll(){
		showLoading();
		$.ajax({ 
			url:"${pageContext.request.contextPath}/account/clear-noty.html",    
			type:"POST", 
			contentType: "application/json; charset=utf-8",
			success: function(response){
				$('#listNotificationCenter').empty();
				function stickyFooter() {
			         var footer = $("#footer");
			         var pos = footer.position();
			         var height = $(window).height();
			         height = height - pos.top;
			         height = height - footer.outerHeight();

			         if (height > 0) {
			          footer.css({
			           'margin-top': height + 'px'
			          });
			         }
			    };
 				$("#borderOfPanel").removeClass("background-secondary");
 				$("#notyCenterBottom").removeClass("border-blue");
 		    	$("#borderOfPanel").removeClass("profile-panel");
 		    	$("#bottomWhenHaveNoty").remove();
 		    	$("#notyCenterBottom").append('<div id="bottomWhenDontHaveNoty"><div class="columns"><span>There are no notification here.</span></div></div>');
 		    	$("#borderOfPanel").css('color','#4189B9');
 		    	$("#borderOfPanel").css('text-align','center');
 		    	NotyManager.clearNotifications();
				NotyManager.decrease(NotyManager.getBubbleCount());
				unShowLoading();				
				stickyFooter();
			}});
	}
	
	function markAllAsRead(){
		showLoading();
		$.ajax({ 
			url:"${pageContext.request.contextPath}/account/mark-all-noty.html",    
			type:"POST", 
			contentType: "application/json; charset=utf-8",
			success: function(response){
				var listNotificationElement = document.getElementsByName("notificationElement");
				for (var i = 0; i < listNotificationElement.length; i++) {
					$(listNotificationElement[i]).removeClass("notification-center-message-background-unread");
					$(listNotificationElement[i]).addClass("notification-center-message-background-read");
				}
				
				var listNotificationTopbar = document.getElementsByName("notyTopbar");
				for (var i = 0; i < listNotificationTopbar.length; i++) {
					$(listNotificationTopbar[i]).removeClass("noty-unread");
				}
				NotyManager.decrease(NotyManager.getBubbleCount());
				unShowLoading();
			}});
	}
	
	
	function submitToSubscribe(notification_id, flightId, spanTag){
		setReadWhenLinkToSuscribe(notification_id);
		showLoading();
		$.ajax({ 
			url:"${pageContext.request.contextPath}/account/check-subscribe-flight-exist.html",    
			type:"POST", 
			contentType: "application/json; charset=utf-8",
			data: flightId, //Stringified Json Object
			success: function(response){
				if(response.length >0){
			 		var notyId = "\"notyform-"+flightId+"\"";
					$('[id='+notyId+']').submit();
				}else{
					generate('error', "The subscribed flight has been deleted");
					var divNotificationBackground = $(spanTag).closest('div').closest('div').closest('div').parent();
					$(divNotificationBackground).removeClass("notification-center-message-background-unread");
					$(divNotificationBackground).addClass("notification-center-message-background-read");
				}
				unShowLoading();
			}});
		

		
	}
	
	$( document ).ready(function() {
	    if($("#bottomWhenDontHaveNoty").length > 0){
	    	$("#notyCenterBottom").removeClass("border-blue");
	    	$("#borderOfPanel").removeClass("profile-panel");
	    	$("#borderOfPanel").removeClass("background-secondary");
	    	$("#borderOfPanel").css('color','#4189B9');
	    	$("#borderOfPanel").css('text-align','center');
	    }
	});
	
// 	$( window ).resize(function() {
// 		$("#borderOfPanel").css('height',$("#heightOfPanel").height() - 2);
// 		});
	
</script>